package com.shuoyue.ycgk.views.video;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.dueeeke.videocontroller.StandardVideoController;
import com.shuoyue.ycgk.R;

public class MyController extends StandardVideoController {
    public MyController(@NonNull Context context) {
        super(context);
    }

    public MyController(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyController(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.my_dkplayer_layout_standard_controller;
    }

    /**
     * 刷新进度回调，子类可在此方法监听进度刷新，然后更新ui
     *
     * @param duration 视频总时长
     * @param position 视频当前时长
     */
    protected void setProgress(int duration, int position) {
        if (progressCallback != null) {
            progressCallback.onprogress(duration, position);
        }
    }

    public void setProgressCallback(ProgressCallback progressCallback) {
        this.progressCallback = progressCallback;
    }

    ProgressCallback progressCallback;

    public interface ProgressCallback {
        void onprogress(int dur, int pos);
    }

    @Override
    public void setCanChangePosition(boolean canChangePosition) {
        super.setCanChangePosition(canChangePosition);
        mLoadingProgress.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return canChangePosition;
            }
        });
    }
}
